/**
 * description
 * <p>fill description</p>
 * @author zido
 * @since 2017/5/30 0030
 */

import browserHistory from 'react-router/lib/browserHistory'
import NProgress from 'nprogress'
export const LOCATION_CHANGE = 'LOCATION_CHANGE'

export const locationChange = (location = '/') => {
  NProgress.start()
  NProgress.set(0.3)
  return {
    type:LOCATION_CHANGE,
    payload:location,
  }
}

//action creator
export const updateLocation = ({dispatch})=>{
  NProgress.start()
  NProgress.set(0.3)
  return nextLocation=> dispatch(locationChange(nextLocation))
}

const initialState = browserHistory.getCurrentLocation()

export const locationReducer = (state = initialState,action) => {
  return action.type === LOCATION_CHANGE? action.payload: state
}

export default locationReducer